<template>
  <div>
    <div class="search-panel">
      <div class="search-input">
        <span class="search-icon"></span>
        <input type="text" v-model="keyword" placeholder="歌手/歌名/拼音" @keydown.enter="search">
      </div>
      <a href="javascript:;" @click="search" class="search-btn">搜索</a>
    </div>

    <div class="search-list" v-show="togglePanel">
      <div class="search-list-title">最近热门</div>
      <mt-cell v-for="(item,index) in hotList" :title="item.keyword" @click.native="seachInput(index)" :key="index"></mt-cell>
    </div>

    <div class="songs-list" v-show="togglePanel2">
      <div class="search-total">
        共有{{total}}条搜索结果
      </div>
       <mt-cell v-for="(item,index) in songList" :title="item.filename" @click.native="playAudio(index)" :key="index">
         <img src="../assets/images/download_icon.png" width="20" height="20">
      </mt-cell>
    </div>
  </div>
</template>
<script>
import {PLAY_AUDIO} from '@/mixins'
import {searchhot} from "@/api"
import {getkeyword} from "@/api"
export default{
mixins:[PLAY_AUDIO],
    data(){
        return{
            keyword:"",
            total:null,
            hotList:[],
            songList:[],
            togglePanel:true,
            togglePanel2:false
        }
    },
    created(){
        this.getlist()
    },
    methods:{
        getlist(){
            searchhot().then(({data})=>{
                console.log(data)
                this.hotList=data.data.info    
            })
        },
         seachInput(index){
            //  console.log(this.hotList[index])
             this.keyword=this.hotList[index].keyword
             this.search()
         },
         search(){
             if(this.keyword){
                 getkeyword(this.keyword).then(({data})=>{
                    //  console.log(data)
                     this.songList=data.data.info
                     this.total=data.data.total
                     this.togglePanel=false;
                     this.togglePanel2=true;
                    //  this.keword=""
                     
                 })
             }
         },
        
    }
}
</script>